$(function(){
	
	//学生ajax      想抽出方法,但是那个回调函数有点迷
	function studentAjax(num){
		$.ajax({
			type:"post",
			url:"/GDZjiajiaowang/adminStu",
			data:{"pageNo":num,"op":"getStudentList"},
			success:function(data){
				
				var th="<div><table class='system_table_style'>";
				th+="<tr><th> 编号</th>";
				th+=	"<th>姓名</th>"
				th+=	"<th>电话</th>"
				th+=	"<th>描述</th>";
				th+=	"<th>更新时间</th>";
				th+=	"<th>操作</th>";
				th+=	"</tr></table></div>";
				$(".system_middle_box_right").append(th);
				$.each(data.studenList,function(index,stu){
					var time="";
					if(!stu.studentDate){
						time="2012年12月12日"
					}else{
						time=change(stu.studentDate);
					}
					
					
					var trr="<tr id='"+stu.studentId+"'><td>";
					trr+= " "+stu.studentId+"</td><td><a href='/GDZjiajiaowang/StudentInfoBeanServlet?studentId="+stu.studentId+"'>"+stu.studentName+"</a></td>";
					trr+=	"<td>"+stu.studentPhone+"</td><td class='level'>"+stu.studentDesc+"</td><td>"+time+"</td>";
					trr+=	"<td>";
						trr+=	"<a href='/GDZjiajiaowang/StudentInfoBeanServlet?studentId="+stu.studentId+"'>查看</a>";
							//trr+=	"<span>|</span>";
								//trr+=	"<span class='update' >编辑</span>";
									trr+=	"<span>|</span>";
										trr+=	"<span class='dle' >删除</span></td></tr>";
												$(".system_table_style").append(trr);//添加到表格
				})
				$(".system_middle_box_right").append("<div id='pageStu' class='page_div'></div>");//将表格添加到div
				
				//..........
				$("#pageStu").paging({
					pageNo: num,
					totalPage: data.totalPages,
					totalSize: data.totalCount,
					callback: function(num) {
						studentAjax(num);
					}
				})
				//...........
			},
			beforeSend:function(){//在触发事件后
				
				$(".system_middle_box_right").empty();//清空右侧
				var head="<p class='function_top'>";
				head+="<input type='button' value='保存操作'class='savestu' />";
				head+="<input type='button' value='撤销会话' class='cancel' />";
				head+="<span class='showTime'></span></p>";
				head+="<p class='function_top_title'>";
				head+="<span><b>学生管理</b>><b>学生</b>列表</span></p>";
				$(".system_middle_box_right").append($(head));//增加保存会话之类的
				//
			}
		})
	}
	//..

	$("#student").click(function(){
		if($(this).attr("disabled")=="disabled"){
			return;
		}
		$("#student").attr("disabled","disabled");
		deleteId=[];//清空 基数
		var pageNo="1";
		studentAjax(pageNo);
		setTimeout("$('#student').removeAttr('disabled')",1000);//三秒后设置 删除disabled
	})
	//保存功能...传递数据到 后台
	$(".system_middle_box_right").on('click','.savestu',function(){//传递后台
		//var json= JSON.stringify(deleteId);//转换为json................
	
		$.ajax({
			type:"post",
			traditional: true,//可以让下面的data   数组,传过去
			dataType:"json",
			url:"/GDZjiajiaowang/adminStu",
			data:{
				"deleteId":deleteId,
				"op":"deleteStudent"
				
			},
		success:function(data){
			//var arr = JSON.parse(data);
			
			alert("删除成功"+data[0]+"失败"+data[1]);
			//删除成功后,前台还留着数据,所以回调 teacherclick 的方法
			$("#student").trigger('click');//...就是刷新
			
		}
		})
	})
})